<?php defined('SYSPATH') or die('No direct script access.');
/**
 * Controller_Show
 *
 * Steuert den Ablauf beim Aufruf eines Bild Links
 *
 * @copyright m.reschke
 * @author m.reschke
 * @version $Id$
 */

class Controller_Show extends Controller_Template_Website
{
    /**
     * Verarbeitet den Aufruf eines 'show' Bildlinks
     *
     */
    public function action_show()
    {
        $config      = Kohana::$config->load('base')->get('default');
        $baseUrl     = URL::base(true);
        $imageName   = $this->request->param('picture');
        $imageFormat = $this->request->param('format');
        $requestUri  = $this->request->uri();
        $showUrl     = $baseUrl . $requestUri;
        $imagePath   = str_replace('show/', $config['upload']['imageDir'], $requestUri);
        $imageUrl    = $baseUrl . $imagePath;
        $thumbUrl    = $baseUrl . $config['upload']['imageDir']
                        . $this->request->param('year')
                        . '/' . $this->request->param('month')
                        . '/' . $config['upload']['thumbDir']
                        . $imageName . '.' . $imageFormat;

        if (file_exists(DOCROOT . $imagePath)) {
            $image      = new Model_Image();
            $imageInfos = $image->getImageInfos(DOCROOT . $imagePath);
            $this->template->title = 'View Image: ' . $imageName . $imageFormat;
            $this->template->content = View::factory('show/show')
                ->set('imageUrl', $imageUrl)
                ->set('showUrl', $showUrl)
                ->set('thumbUrl', $thumbUrl)
                ->set('imageName', $imageName)
                ->set('imageFormat', $imageFormat)
                ->set('infos', $imageInfos);
        } else {
            $this->template->title = 'Error';
            $this->template->content = View::factory('error/error');
        }

    }

    public function action_download()
    {
//        $file = 'image/2013/02/qkipuxe7czsefitnfnmd.jpg';
//        $this->request->headers('Content-type', 'image/jpeg');
//        $this->request->headers('Content-Disposition', $file);
//        readfile($file);
//        $param = $this->request->headers();
//        var_dump($post); exit;
    }
}